import wx
import wx.lib.mixins.listctrl
from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor

##  New bony landmark 3D coordinates can be chosen using this menu.
class AddBLFrame(wx.Frame):
    ##  The constructor of AddBLFrame. GUI elements of the panel are setup here.
    #   @param[in]  gui     GUI instance.
    #   @param[in]  *args   Automatically passed parameter.
    #   @param[in]  **kwds  Automatically passed parameter.
    def __init__(self, gui, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        ##  The Panel on which we are attaching our GUI.
        self.panel_1 = wx.Panel(self, -1)
        ##  Gui instance.
        self.gui = gui
        ##  The list for the 3D coordinates.
        self.bony_landmarks_listctrl = CoordinatesListCtrl(self, -1, style=wx.LC_REPORT|wx.LC_NO_HEADER|wx.LC_SINGLE_SEL|wx.SUNKEN_BORDER)
        ##  Displays a help dialog.
        self.help_button = wx.Button(self.panel_1, -1, "Help")
        ##  Finishes picking points and closes the panel.
        self.finish_button = wx.Button(self.panel_1, -1, "Finish")
        ##  wxVTKRenderWindowInteractor used to show the 3D model.
        self.rwi = wxVTKRenderWindowInteractor(self.panel_1, -1)

        self.__set_properties()
        self.__do_layout()

    ##  Sets properties for the panel.
    def __set_properties(self):
        self.SetTitle("Bony Landmarks Editor")
        self.SetIcon(wx.Icon(self.gui.main.config.root+"\\Images\\icon.ico", wx.BITMAP_TYPE_ICO, 32, 32))

    ##  Sets layout for the panel.
    def __do_layout(self):
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_3 = wx.BoxSizer(wx.VERTICAL)
        sizer_4 = wx.BoxSizer(wx.VERTICAL)
        sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_7 = wx.BoxSizer(wx.VERTICAL)
        sizer_6 = wx.BoxSizer(wx.VERTICAL)
        sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_6.Add(self.bony_landmarks_listctrl, 1, wx.EXPAND, 0)
        sizer_8.Add(self.help_button, 0, wx.RIGHT|wx.ALIGN_CENTER_HORIZONTAL, 4)
        sizer_8.Add(self.finish_button, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
        sizer_6.Add(sizer_8, 0, wx.TOP|wx.EXPAND, 7)
        sizer_5.Add(sizer_6, 0, wx.RIGHT|wx.EXPAND, 7)
        sizer_7.Add(self.rwi, 1, wx.EXPAND, 0)
        sizer_7.Add((450, 0), 0, 0, 0)
        sizer_5.Add(sizer_7, 1, wx.EXPAND, 0)
        sizer_5.Add((0, 480), 0, 0, 0)
        sizer_4.Add(sizer_5, 1, wx.EXPAND, 0)
        sizer_3.Add(sizer_4, 1, wx.ALL|wx.EXPAND, 7)
        self.panel_1.SetSizer(sizer_3)
        sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()

##  List for the 3D coordinates.
#   Here, wx.ListCtrl is used with ListCtrlAutoWidthMixin to create fitting columns.
class CoordinatesListCtrl(wx.ListCtrl, wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin):
    ##  The constructor of CoordinatesListCtrl.
    def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
        wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
        wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin.__init__(self)
        self.InsertColumn(0, "Column 1")